package com.graduation.fq.student.Logic;

import com.graduation.fq.student.Args.ScoreEventArgs;
import com.graduation.fq.student.Args.SimpleEventArgs;
import com.graduation.fq.student.Process.ScoreProcess;
import com.graduation.fq.student.Utils.ScoreUrlIndex;
import com.graduation.fq.student.interfaces.EventListener;
import com.graduation.fq.student.interfaces.ResponseListener;

/**
 * Created by jifang
 * Time 2016/5/27 20:33.
 */
public class ScoreLogic extends BaseLogic {

    private static ScoreLogic instance;

    public static ScoreLogic getInstance() {
        if (instance == null) {
            instance = new ScoreLogic();
        }
        return instance;
    }

    public void scoreList(Integer uId, final EventListener listener){
        final ScoreProcess process = new ScoreProcess(ScoreUrlIndex.SCORE_LIST, uId, null);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                ScoreEventArgs args = new ScoreEventArgs(process.getStatus(), process.getScores());
                fireEvent(args, listener);
            }
        });
    }

    public void scoreTopN(Integer uId, Integer n, final EventListener listener){
        final ScoreProcess process = new ScoreProcess(ScoreUrlIndex.SCORE_TOP_N, uId, n);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                ScoreEventArgs args = new ScoreEventArgs(process.getStatus(), process.getScores());
                fireEvent(args, listener);
            }
        });
    }

    public void scoreUnPassed(Integer uId, final EventListener listener){
        final ScoreProcess process = new ScoreProcess(ScoreUrlIndex.SCORE_UN_PASSED, uId, null);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                ScoreEventArgs args = new ScoreEventArgs(process.getStatus(), process.getScores());
                fireEvent(args, listener);
            }
        });
    }

    public void scoreTotal(Integer uId, final EventListener listener){
        final ScoreProcess process = new ScoreProcess(ScoreUrlIndex.SCORE_TOTAL, uId, null);
        process.runGet(new ResponseListener() {
            @Override
            public void onResponse(String requestId) {
                SimpleEventArgs<Double> args = new SimpleEventArgs<Double>(process.getStatus(), process.getTotal());
                fireEvent(args, listener);
            }
        });
    }
}
